package com.secxiot.provider.config;

import com.secxiot.common.exception.BaseException;
import com.secxiot.provider.task.service.TaskService;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.logging.Level;

@Log
@Component
@EnableScheduling
public class TaskTimer {

    @Autowired
    private TaskService taskService;

    @Scheduled(cron = "0/10 * * * * ?")
    private void pushPublishNotice() {
        LocalDateTime date = LocalDateTime.now();
        String format = date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        log.log(Level.INFO, "发布任务提醒:" + format);
        taskService.pushPublishNotice();
    }

    @Scheduled(cron = "0/10 * * * * ?")
    private void timeSosTask() throws BaseException {
        LocalDateTime date = LocalDateTime.now();
        String format = date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        log.log(Level.INFO, "获取sos任务状态:" + format);
        taskService.timeSosTask();
    }

    @Scheduled(cron = "0/10 * * * * ?")
    private void pushSMSNotice() {
        LocalDateTime date = LocalDateTime.now();
        String format = date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        log.log(Level.INFO, "发布任务短信提醒:" + format);
        taskService.pushSMSNotice();
    }
}
